package com.jingdianjichi.oss.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jingdianjichi.oss.adapter.FileService_adapter;
import com.jingdianjichi.oss.service.FileService;
import com.jingdianjichi.oss.service.impl.AliStorageServiceImpl;
import com.jingdianjichi.oss.service.impl.MinioStorageServiceImpl;
import com.jingdianjichi.oss.utils.MinioUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class testController {

    /**
     * 测试minio的链接
     */
    @Resource
    private MinioUtil minioUtil;


    @RequestMapping("/testGetAllBucket1")
    public String testGetAllBucket1() throws Exception {
        List<String> allBucket = minioUtil.getAllBucket();

        return allBucket.get(0);
    }


    /**
     * 传统模式的实现底层的切换,但是这样的话还是要在切换的时候来修改代码的
     */
    @Resource
    private MinioStorageServiceImpl storageService1;


    @RequestMapping("/testGetAllBucket2")
    public String testGetAllBucket2() throws Exception {
        List<String> allBucket = storageService1.getAllBucket();

        return allBucket.get(0);
    }

    @Resource
    private AliStorageServiceImpl storageService2;


    @RequestMapping("/testGetAllBucket3")
    public String testGetAllBucket3() throws Exception {
        List<String> allBucket = storageService2.getAllBucket();

        return allBucket.get(0);
    }


    /**
     * 使用抽象类的方式实现,适配器,模式来的,但是使用这个抽象类来实现的话,缺点就是每个实现类如果差别非常大的话
     *      /我们的接口是没法做统一管理的
     */
    @Resource
    private FileService fileService;

    @RequestMapping("/testGetAllBucket4")
    public String testGetAllBucket4() throws Exception {
        List<String> allBucket = fileService.getAllBucket();

        return allBucket.get(0);
    }


    /**
     * 使用new的方式实现适配器模式
     */
    @Resource
    private FileService_adapter fileService_adapter;

    @RequestMapping("/testGetAllBucket5")
    public String testGetAllBucket5() throws Exception {
        List<String> allBucket = fileService_adapter.getAllBucket();

        return allBucket.get(0);
    }


}
